package com.ls.designModel;

import java.io.Serializable;

/**
 * 饿汉式
 */
public class HungerSingle implements Serializable {

    private static final HungerSingle INSTANCE = new HungerSingle();

    private HungerSingle() {
        if (INSTANCE!=null){
            throw new RuntimeException("单例模式禁止反射破坏");
        }
        System.out.println("constructor");
    }

    /**
     * 便于观察
     * @return
     */
    public static HungerSingle getInstance(){
        return INSTANCE;
    }

    public static void otherMethod(){
        System.out.println("otherMethod...");
    }

    public Object readResolve(){
        return INSTANCE;
    }
}
